﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ucMenutree.ascx.cs" Inherits="BaseSystem._System.UserControl.ucMenutree" %>
<script type="text/javascript">
   <!--
   //<![CDATA[

function public_GetParentByTagName(element, tagName)
{
       var parent = element.parentNode;
       var upperTagName = tagName.toUpperCase();

       while (parent && (parent.tagName.toUpperCase() != upperTagName))
       {
         parent = parent.parentNode ? parent.parentNode : parent.parentElement;
       }
       return parent;
}


function setParentChecked(objNode)
{
       var objParentDiv = public_GetParentByTagName(objNode,"div");
       if(objParentDiv==null || objParentDiv == "undefined")
       {
         return;
       }
       var objID = objParentDiv.getAttribute("ID");
       objID = objID.substring(0,objID.indexOf("Nodes"));
       objID = objID+"CheckBox";
       var objParentCheckBox = document.getElementById(objID);
       if(objParentCheckBox==null || objParentCheckBox == "undefined")
       {
         return;
       }
       if(objParentCheckBox.tagName.toLowerCase() != "input" && objParentCheckBox.type == "checkbox")
       return;
       objParentCheckBox.checked = true;
       setParentChecked(objParentCheckBox);
}

function setChildUnChecked(divID)
{
       var objchild = divID.children;
       var count = objchild.length;
       for(var i=0;i <objchild.length;i++)
       {
         var tempObj = objchild[i];
         if(tempObj.tagName.toLowerCase() == "input" && tempObj.type == "checkbox")
         {
            tempObj.checked = false;
         }
         setChildUnChecked(tempObj);
       }
}


function setChildChecked(divID)
{
       var objchild = divID.children;
       var count = objchild.length;

       for(var i=0;i <objchild.length;i++)
       {
         var tempObj = objchild[i];
         if(tempObj.tagName.toLowerCase() =="input" && tempObj.type == "checkbox")
         {
            tempObj.checked = true;
         }
         setChildChecked(tempObj);
       }
}

function setParentUnChecked(divID)
{
       var objchild = divID.children;
       var count = objchild.length;
if(count>0)
{
alert(count);
       for(var i=0;i <objchild.length;i++)
       {
         var tempObj = objchild[i];
         if(tempObj.tagName.toLowerCase() =="input" && tempObj.type == "checkbox" && tempObj.checked == true)
         {  
            divID.checked=false;
            i++;
            break;
         }
       }
}
}
//
function CheckEvent()
{

       var objNode = event.srcElement;

       if(objNode.tagName!="INPUT" || objNode.type!="checkbox")
       return;
       if(objNode.checked==true)
       {
         setParentChecked(objNode);
         var objID = objNode.getAttribute("ID");
         var objID = objID.substring(0,objID.indexOf("CheckBox"));
         var objParentDiv = document.getElementById(objID+"Nodes");
         if(objParentDiv==null || objParentDiv == "undefined")
         {
            return;
         }
         setChildChecked(objParentDiv);
       }
       else
       {
         var objID = objNode.getAttribute("ID");
         var objID = objID.substring(0,objID.indexOf("CheckBox"));
         var objParentDiv = document.getElementById(objID+"Nodes");
         if(objParentDiv==null || objParentDiv == "undefined")
         {
            return;
         }
         setChildUnChecked(objParentDiv);
//         setParentUnChecked(objParentDiv);
       }
} 
   //]]>
	// -->
</script>

<asp:TreeView ID="trRoles" runat="server" ShowCheckBoxes="All" ShowLines="True" CssClass="TreeViewStyle"  >
    <ParentNodeStyle  CssClass="TreeViewParentNodeStyle" />
    <RootNodeStyle  CssClass="TreeViewRootNodeStyle" />
    <NodeStyle  CssClass="TreeViewNodeStyle" />
    <HoverNodeStyle  CssClass="TreeViewHoverNodeStyle" />
    <SelectedNodeStyle  CssClass="TreeViewSelectedNodeStyle" />
    <LeafNodeStyle  CssClass="TreeViewLeafNodeStyle"  />

</asp:TreeView>


